<?php
namespace App\Controllers\Index;
include __DIR__.'/../../vendor/phpqrcode/qrlib.php';
use App\Models\Experience\ExpOrder;
use App\Libs\Helper\CryptHelper;
/**
*	生成支付二维码体验
*/
class QrcodeOrderEx extends \App\Libs\Base\BaseAction
{
    protected function beforeRun() {
        parent::beforeRun();
        $this->needLogin = TRUE;
    }
	
	public function execute(){
		//订单号是否为空
		$user = $this->session->user;
		$expOrder_id = $this->request->get('order_id');
		if( empty($expOrder_id) ){
			return \App\Libs\Views\Json::view(1, '订单号不能为空', null);
		}
		//订单是否存在
		$order = ExpOrder::find(array(
			' id = :expOrder_id: and status = 2 and uid = :uid:',
			'bind' => array( 'expOrder_id'=>$expOrder_id , 'uid'=>$user->id )
		));
		if( empty( $order ) ){
			return \App\Libs\Views\Json::view(1, '订单不存在', null);	
		}else{
			$order = $order->toArray();
		}
		
		//加密 时间戳 + 用户id + 订单号  + 标志号1：订单 2.体验订单
		$str = time() . '_' . $user->id . '_' . $order['id'] .'_2';
		$encryptVal = CryptHelper::encrypt( $str );
		$encryptVal = str_replace('+','_*_',$encryptVal);

		\QRcode::png($encryptVal);	
		die;
	}
}
